package Thread.Thread_Attributes;

public class Demo16 {
    //线程引用的获取
    public static void main(String[] args) throws InterruptedException {
        //例如让其他线程去等待主线程main
        //获取main线程
        Thread mainThread=Thread.currentThread();
        //任何线程中都可以通过这样的方式来获取线程的引用
        Thread t=new Thread(()->{
           //需要在t中调用.join
            System.out.println("t 线程开始等待");
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t线程等待结束");
        });
        t.start();
        Thread.sleep(2000);
        System.out.println("main 主线程结束");
    }
}
